import 'package:flutter/material.dart';
import 'package:zhaoxiansheng_app/pages/Home.dart';
import 'package:zhaoxiansheng_app/pages/Search.dart';
import 'package:zhaoxiansheng_app/pages/Person.dart';
import 'package:zhaoxiansheng_app/pages/test.dart';
import 'package:get/get.dart';
import 'package:get_storage/get_storage.dart';
import 'package:zhaoxiansheng_app/pages/login/login.dart';
import 'package:zhaoxiansheng_app/controller/ThemeController.dart';
import 'package:zhaoxiansheng_app/controller/LoginController.dart';

void main() async {
  await GetStorage.init();
  Get.put(ThemeController());
  Get.put(LoginController());
  runApp(MyApp());
  // var  storage = GetStorage();
  // Person userInfo = await storage.read("userInfo");
  // print("userInfo: ${userInfo}");
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return GetMaterialApp(
      initialRoute: "/",
      getPages: [
        GetPage(
          name: "/login",
          page: () => LoginPage(),
          transition: Transition.native,
        ),
        GetPage(name: "/home", page: () => Home(), transition: Transition.fade),
      ],
      home: Scaffold(body: MainPageState()),
      theme: ThemeData.light(),
      darkTheme: ThemeData.dark(),
      themeMode: ThemeMode.system,
    );
  }
}

class MainPageState extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return MainPage();
  }
}

class MainPage extends State<MainPageState> {
  @override
  void initState() {
    super.initState();
  }

  var _currentIndex = 0;
  List<Widget> _pages = [Home(), Search(), Person(), TestPage()];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Padding(
        padding: EdgeInsetsGeometry.all(10),
        child: _pages[_currentIndex],
      ),
      bottomNavigationBar: Container(
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.only(
            topLeft: Radius.circular(20),
            topRight: Radius.circular(20),
          ),
          boxShadow: [
            BoxShadow(
              color: Colors.black12,
              blurRadius: 10,
              offset: Offset(0, -2),
            ),
          ],
        ),
        child: ClipRRect(//裁剪
          borderRadius: BorderRadius.only(
            topLeft: Radius.circular(20),
            topRight: Radius.circular(20),
          ),
          child: BottomNavigationBar(
            type: BottomNavigationBarType.fixed,
            backgroundColor: Colors.white,
            selectedItemColor: Colors.deepPurple, // 选中颜色
            unselectedItemColor: Colors.grey, // 未选中颜色
            selectedLabelStyle: TextStyle(fontWeight: FontWeight.bold),
            unselectedLabelStyle: TextStyle(color: Colors.grey),
            showUnselectedLabels: true, // 显示未选中标签
            currentIndex: _currentIndex,
            elevation: 0,
            items: [
              BottomNavigationBarItem(icon: Icon(Icons.house), label: "主页"),
              BottomNavigationBarItem(icon: Icon(Icons.search), label: "发现"),
              BottomNavigationBarItem(icon: Icon(Icons.person), label: "个人"),
              BottomNavigationBarItem(
                icon: Icon(Icons.textsms_sharp),
                label: "测试",
              ),
            ],
            onTap: (index) {
              if (index == 0) {
                Get.snackbar(
                  "欢迎",
                  "感谢您来到我的APP",
                  colorText: Colors.white,
                  icon: Icon(Icons.cloud_done, color: Colors.white),
                  duration: Duration(seconds: 1),
                  borderRadius: 20,
                  backgroundColor: Colors.deepPurple,
                  borderWidth: 0.5,
                  borderColor: Colors.amber,
                );
              }
              setState(() {
                _currentIndex = index;
              });
            },
          ),
        ),
      ),
    );
  }
}
